home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / forth / pfe-0.000 / pfe-0 / pfe-0.9.13 / src / check_c.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-17  |  3.5 KB  |  149 lines

  1. /*
  2.  * This file is part of the portable Forth environment written in ANSI C.
  3.  * Copyright (C) 1995  Dirk Uwe Zoller
  4.  *
  5.  * This library is free software; you can redistribute it and/or
  6.  * modify it under the terms of the GNU Library General Public
  7.  * License as published by the Free Software Foundation; either
  8.  * version 2 of the License, or (at your option) any later version.
  9.  *
  10.  * This library is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13.  * See the GNU Library General Public License for more details.
  14.  *
  15.  * You should have received a copy of the GNU Library General Public
  16.  * License along with this library; if not, write to the Free
  17.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  * This file is version 0.9.13 of 17-July-95
  20.  * Check for the latest version of this package via anonymous ftp at
  21.  *    roxi.rz.fht-mannheim.de:/pub/languages/forth/pfe-VERSION.tar.gz
  22.  * or    sunsite.unc.edu:/pub/languages/forth/pfe-VERSION.tar.gz
  23.  * or    ftp.cygnus.com:/pub/forth/pfe-VERSION.tar.gz
  24.  *
  25.  * Please direct any comments via internet to
  26.  *    duz@roxi.rz.fht-mannheim.de.
  27.  * Thank You.
  28.  */
  29. /*
  30.  * check_c.c --- Determine some C-compiler properties.
  31.  * (duz 24Apr94)
  32.  */
  33.  
  34. #include <stdio.h>
  35. #include <string.h>
  36. #include <signal.h>
  37.  
  38. #define OFFSET(X,C)    (int)((char *)&(X.C) - (char *)&(X))
  39. #define CELLSIZE    (sizeof (void *))
  40.  
  41. void sig_hdl (int sig) {}
  42.  
  43. int
  44. main ()
  45. {
  46.   union
  47.     {
  48.       char c[sizeof (long)];
  49.       int i;
  50.       long l;
  51.     }
  52.   t;
  53.   struct
  54.     {
  55.       char c;
  56.       int i;
  57.     }
  58.   ti;
  59.   struct
  60.     {
  61.       char c;
  62.       long l;
  63.     }
  64.   tl;
  65.   struct
  66.     {
  67.       char c;
  68.       float f;
  69.     }
  70.   tf;
  71.   struct
  72.     {
  73.       char c;
  74.       double d;
  75.     }
  76.   td;
  77.   int cellalign, sfloatalign, dfloatalign;
  78.  
  79.   memset (t.c, 0, sizeof t.c);
  80.   /*
  81.    * determine types for CELL and HALFCELL:
  82.    */
  83.   if (sizeof (int) == CELLSIZE)
  84.     {
  85.       t.i = 1;
  86.       cellalign = OFFSET (ti, i);
  87.       puts ("#define CELL_TYPE int");
  88.       if (sizeof (short) == sizeof (int) / 2)
  89.       puts ("#define HALF_CELL_TYPE short");
  90.  
  91.       else
  92.     puts ("#define HALF_CELL_TYPE char");
  93.     }
  94.   else if (sizeof (long) == CELLSIZE)
  95.     {
  96.       t.l = 1;
  97.       cellalign = OFFSET (tl, l);
  98.       puts ("#define CELL_TYPE long");
  99.       if (sizeof (int) == sizeof (long) / 2)
  100.       puts ("#define HALF_CELL_TYPE int");
  101.       else if (sizeof (short) == sizeof (long) / 2)
  102.       puts ("#define HALF_CELL_TYPE short");
  103.  
  104.       else
  105.     puts ("#define HALF_CELL_TYPE char");
  106.     }
  107.   else
  108.     puts ("#error \"could not determine type for Cell\"");
  109.  
  110.   /*
  111.    * Determine endianess:
  112.    */
  113.   if (t.c[0] == 1)
  114.     puts ("#define HIGHBYTE_FIRST 0");
  115.   else
  116.     puts ("#define HIGHBYTE_FIRST 1");
  117.  
  118.   /*
  119.    * Determine alignment restrictions:
  120.    */
  121.   printf ("#define CELLSIZE %d\n", (int)CELLSIZE);
  122.   printf ("#define SFLOATSIZE %d\n", (int)sizeof (float));
  123.   printf ("#define DFLOATSIZE %d\n", (int)sizeof (double));
  124.  
  125.   sfloatalign = OFFSET (tf, f);
  126.   dfloatalign = OFFSET (td, d);
  127.  
  128.   if (cellalign < CELLSIZE)
  129.     cellalign = CELLSIZE;
  130.   if (sfloatalign < cellalign)
  131.     sfloatalign = cellalign;
  132.   if (dfloatalign < sfloatalign)
  133.     dfloatalign = sfloatalign;
  134.  
  135.   printf ("#define CELL_ALIGN %d\n", cellalign);
  136.   printf ("#define SFLOAT_ALIGN %d\n", sfloatalign);
  137.   printf ("#define DFLOAT_ALIGN %d\n", dfloatalign);
  138.  
  139.   /*
  140.    * Determine if signals must be reinstalled:
  141.    */
  142.   signal (SIGTERM, sig_hdl);
  143.   raise (SIGTERM);
  144.   if (signal (SIGTERM, SIG_DFL) == sig_hdl)
  145.     puts ("#define KEEPS_SIGNALS 1");
  146.  
  147.   return 0;
  148. }
  149.